<?php
$this->breadcrumbs=array(
	$model->category->title => array('/Events/categories/view', 'url'=>$model->category->url),
	$model->title,
);
$this->pageTitle = $model->seotool->title;
$this->pageDescription = $model->seotool->description;
$this->pageKeywords = $model->seotool->keywords;
$this->pageCanonical = array('/Events/default/view', array('category'=>$model->category->url, 'url'=>$model->url));
$this->pageRobotsFollow = 'nofollow';

$this->pageFacebook=array(
    'og:title'=>$model->seotool->title,
    'og:author'=>SITE_AUTHOR,
    'og:type'=>'article',
    'og:image'=>'events/primary/' . date('Ymd', strtotime($model->posteddate)) . '/' . $model->image,
    'og:url'=>array('/Events/default/view', array('category'=>$model->category->url, 'url'=>$model->url)),
    'og:description'=>$model->seotool->description,
    'og:locale'=>'vi_VN',
);

?>
<article class="event-detail">
    <div class="row">
    	<div class="col-xs-9">
            <div class="event-primary">
            	<h1 class="event-title"><?php echo $model->title; ?></h1>
                <!-- Event time, count down, place -->
                <div class="event-header box bg-grey">
                    <div class="event-col event-date event-right">
                        <div class="rows">
                            <div class="col-xs-5 text-right event-date-day">
                                <?php echo date('d', strtotime($model->startdate)); ?>
                            </div>
                            <div class="col-xs-7 event-date-month">
                                <span class="btn-block">
                                    <?php echo date('\T\h\á\n\g m', strtotime($model->startdate)); ?>
                                </span>
                                <span class="btn-block">
                                    <?php echo date('Y', strtotime($model->startdate)); ?>
                                </span>
                            </div>
                        </div>
                    </div>
                    <div class="event-col event-countdown event-right">
                        <?php if (strtotime($model->startdate) >= time()) {
                            echo '<p>Sự kiện sắp diễn ra ...</p>';
						}
						else if (strtotime($model->startdate) <= time() && strtotime($model->enddate) >= time()) {
							echo '<p>Sự kiện đang diễn ra</p>';
						}
						else {
							echo '<p>Sự kiện đang diễn ra</p>';
						}?>
                            <div class="countdown text-center" data-time="<?php echo date('Y/m/d H:i:s', strtotime($model->startdate)); ?>">
                            </div>
                    </div>
                    <div class="event-col">
                        <div class="event-location">
                            <div class="event-location-content">
                                <p><span class="glyphicon glyphicon-time"></span>&nbsp;Từ: <?php echo ucwords(strftime('%H:%M - %A, ngày %d-%m-%Y', strtotime($model->startdate))); ?>
                                <br /><span class="glyphicon"></span>&nbsp;Đến: <?php echo ucwords(strftime('%H:%M - %A, ngày %d-%m-%Y', strtotime($model->enddate))); ?>
                                </p>
                                <p><span class="glyphicon glyphicon-map-marker"></span>&nbsp;
                                <?php if (!empty($model->location)) {
                                    // Kiểm tra xem có bản ghi địa điểm hay không
                                    if ($model->location->place_id == 0) {
                                        // Lấy thông tin từ bản ghi EventLocations
                                        if (!empty($model->location->title)) { echo $model->location->title; };
                                        if (!empty($model->location->address)) { echo ', ' . $model->location->address; };
                                        if (!empty($model->location->ward)) { echo ', ' . $model->location->ward; };
                                        if (!empty($model->location->district)) { echo ', ' . $model->location->district; };
                                        if (!empty($model->location->city)) { echo ', ' . $model->location->city; };
                                    }
                                    elseif (!empty($model->location->place)) {
                                        // Lấy thông tin từ bản ghi Places
                                        if (!empty($model->location->place->title)) { echo $model->location->title; };
                                        if (!empty($model->location->place->location->address)) { echo ', ' . $model->location->place->location->address; };
                                        if (!empty($model->location->place->location->ward)) { echo ', ' . $model->location->place->location->ward; };
                                        if (!empty($model->location->place->location->district)) { echo ', ' . $model->location->place->location->district; };
                                        if (!empty($model->location->place->location->city)) { echo ', ' . $model->location->place->location->city; };
                                    }
                                    else {
                                        echo 'Vui lòng liên hệ';
                                    }
                                } ?>
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Event content -->
                <div class="event-body">
                	<div class="event-image text-center">
                		<img src="<?php echo IMAGES_URL . 'events/primary/' , date('Ymd', strtotime($model->posteddate)) , '/', $model->image; ?>" alt="<?php echo $model->title; ?>" />
                    </div>
                    <div class="event-content">
                        <?php if (!empty($model->content)): ?>
                    	<?php echo $model->content->description; ?>
                        <?php endif; ?>
                    </div>
                    <!-- Event Chart -->
                    <?php if (!empty($model->chart)) : ?>
                    <div class="event-chart">
                    	<img src="<?php echo IMAGES_URL . 'events/charts/' , date('Ymd', strtotime($model->posteddate)) , '/', $model->chart->image; ?>" alt="<?php echo $model->chart->title; ?>" />
                    </div>
                    <?php endif; ?>
                </div>
                <!-- Event contact & Booking -->
                <div class="event-contact box bg-grey">
                	<div class="row">
                    	<div class="col-xs-6">
                        	<p>Thông tin liên hệ</p>
                            <?php foreach($model->contacts as $contact):?>
                            <strong class="btn-block"><?php echo $contact->company; ?></strong>
                            <div class="event-contact">
                                <dl class="row">
                                    <dt class="col-xs-6"><?php echo $contact->prename.' '.$contact->fullname; ?></dt>
                                    <dd class="col-xs-6 text-right"><?php echo $contact->phone; ?></dd>
                                </dl>
                                <div class="clear"></div>
                            </div>
                            <?php endforeach; ?>
                        </div>
                        <div class="col-xs-3 col-xs-offset-3">
                            <?php if ($model->ticket !== 'F'): ?>
                        	<?php echo CHtml::link('Tham gia', array('/Events/default/order', 'category'=>$model->category->url, 'url'=>$model->url), array('title'=>'Tham gia', 'class'=>'btn-block btn btn-success')); ?>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
                <!-- Event Tags -->
                <?php if (!empty($model->label)): ?>
                <div class="event-tag">
                    <strong>TAG</strong>: <?php foreach ($model->label as $x => $data) {
                        echo CHtml::link($data->title, array('/Home/labels/view', 'slug'=>$data->slug), array('title'=>'Sự kiện trong nhãn ' . $data->title));
                        if ($x != count($model->label)-1) {
                            echo ', ';
                        }
                    } ?>
                </div>
                <?php endif; ?>
                <!-- Event Social -->
                <h3 class="event-share">Chia sẻ và bình luận</h3>
                <div class="event-social">
                	<div class="event-social-item">
                    	<div class="fb-like" data-href="<?php echo Yii::app()->createAbsoluteUrl('/Events/default/view',array('category'=>$model->category->url, 'url'=>$model->url)); ?>" data-width="450" data-layout="button_count" data-show-faces="true" data-send="false"></div>
                    </div>
                    <div class="event-social-item">
	                    <a href="https://twitter.com/NEXTTOPEVENT" class="twitter-follow-button" data-show-count="false" data-lang="en">Follow</a>
                    </div>
                    <div class="event-social-item">
                    	<g:plusone annotation="bubble" size="medium"></g:plusone>
                    </div>
                    <div class="clear"></div>
                </div>
                <!-- Event Facebook Comment -->
                <div class="fb-comments" data-href="<?php echo Yii::app()->createAbsoluteUrl('/Events/default/view',array('category'=>$model->category->url, 'url'=>$model->url)); ?>" data-width="773"></div>
            </div>
        </div>
        <div class="col-xs-3">
        	<!-- Event Tickets -->
            <?php if (!empty($model->tickets)): ?>
        	<aside class="widget event-tickets">
            	<h3>Loại vé</h3>
                <div class="ticket-list">
                <?php foreach ($model->tickets as $ticket) : ?>
                	<div class="ticket-item row">
                    	<div class="col-xs-6">
                        	<span class="ticket-title"><?php echo $ticket->title; ?></span>
                        </div>
                        <div class="col-xs-6 text-right">
                        	<span class="ticket-price"><?php echo number_format($ticket->price, 0, ',', '.'); ?> VNĐ</span>
                        </div>
                    </div>
                <?php endforeach; ?>
                </div>
            </aside>
            <?php endif; ?>

        	<!-- Event Contact -->
        	<aside class="widget box bg-grey event-booking">
                <h3>Liên hệ đặt vé</h3>

                <?php foreach($model->contacts as $contact):?>
                    <strong class="btn-block"><?php echo $contact->company; ?></strong>
                    <div class="event-contact">
                        <dl class="row">
                            <dt class="col-xs-6"><?php echo $contact->prename.' '.$contact->fullname; ?></dt>
                            <dd class="col-xs-6 text-right"><?php echo $contact->phone; ?></dd>
                        </dl>
                        <div class="clear"></div>
                    </div>
                <?php endforeach; ?>
                <?php if ($model->ticket !== 'F'): ?>
                <?php echo CHtml::link('<strong>Đặt vé</strong>', array('/Events/default/order', 'category'=>$model->category->url, 'url'=>$model->url), array('title'=>'Đặt vé tham gia sự kiện', 'class'=>'btn btn-success btn-block')); ?>

                <p class="text-center">Mua vé dễ dàng và nhanh chóng.</p>
                <?php endif; ?>
            </aside>
            <?php /*
            <!-- Event Maps -->
            <aside class="widget box box-border">
            	<h3>Địa điểm tổ chức</h3>
                <div id="map_canvas" style="height:250px;"></div>
                <p id="map_address">
					<?php if (!empty($model->location)) {
						// Kiểm tra xem có bản ghi địa điểm hay không
						if ($model->location->place_id == 0) {
							// Lấy thông tin từ bản ghi EventLocations
							if (!empty($model->location->title)) { echo $model->location->title; };
							if (!empty($model->location->address)) { echo ', ' . $model->location->address; };
							if (!empty($model->location->ward)) { echo ', ' . $model->location->ward; };
							if (!empty($model->location->district)) { echo ', ' . $model->location->district; };
							if (!empty($model->location->city)) { echo ', ' . $model->location->city; };
						}
						elseif (!empty($model->location->place)) {
							// Lấy thông tin từ bản ghi Places
							if (!empty($model->location->place->title)) { echo $model->location->title; };
							if (!empty($model->location->place->location->address)) { echo ', ' . $model->location->place->location->address; };
							if (!empty($model->location->place->location->ward)) { echo ', ' . $model->location->place->location->ward; };
							if (!empty($model->location->place->location->district)) { echo ', ' . $model->location->place->location->district; };
							if (!empty($model->location->place->location->city)) { echo ', ' . $model->location->place->location->city; };
						}
						else {
							echo 'Vui lòng liên hệ';
						}
					} ?></p>
            </aside>
            */ ?>
            <!-- Event Calendar -->
        	<aside class="widget box bg-grey">
                <h3>Lịch sự kiện</h3>
                <div id="calendar"></div>
                <div id="calendar-event" class="event-small"></div>
            </aside>

            <!-- Event in Category -->
        	<aside class="widget box bg-grey">
                <h3>Sự kiện cùng danh mục</h3>
                <div class="event-small">
                <?php foreach ($events as $data): ?>
                    <div class="event-item media">
                    	<a class="pull-left" href="<?php echo Yii::app()->createurl('/Events/default/view', array('category'=>$data->category->url, 'url'=>$data->url)); ?>" title="<?php echo $data->title; ?>">
                        	<img class="media-object" src="<?php echo IMAGES_URL . 'events/thumbs/' , date('Ymd', strtotime($data->posteddate)), '/', $data->image; ?>" alt="<?php echo $data->title; ?>" width="64" height="40">
                        </a>
                        <div class="media-body">
                        	<h4 class="media-heading"><?php echo CHtml::link($data->title, array('/Events/default/view', 'category'=>$data->category->url, 'url'=>$data->url), array('title'=>$data->title)); ?></h4>
                        </div>
                    </div>
                <?php endforeach; ?>
                	<div class="text-center bg-white box">
                    	<?php echo CHtml::link('XEM TẤT CẢ', array('/Events/categories/view', 'url'=>$model->category->url), array('title'=>'Xem các sự kiện khác cùng danh mục ' . $model->category->title)); ?>
                    </div>
                </div>
            </aside>
            <!-- Artist -->
            <?php if (!empty($model->artists)): ?>
            <aside class="widget">
                <h3 class="box box-border">Nhân vật - Sự kiện</h3>
                <div class="box-border event-small">
                <?php foreach ($model->artists as $data): ?>
                    <div class="event-item">
                        <div class="event-image">
                            <a href="<?php echo Yii::app()->createurl('/Events/artists/view', array('slug'=>$data->url)); ?>" title="<?php echo $data->nickname; ?>">
                                <img src="<?php echo IMAGES_URL . 'artists/' . date('Ymd', strtotime($data->createddate)) . '/' . $data->image; ?>" alt="<?php echo $data->nickname; ?>" />
                            </a>
                        </div>
                        <div class="event-content">
                            <?php echo CHtml::link($data->nickname, array('/Events/artists/view', 'slug'=>$data->url), array('title'=>$data->nickname)); ?>
                        </div>
                    </div>
                <?php endforeach; ?>
                </div>
            </aside>
            <?php endif; ?>
        </div>
    </div>
</article>

<?php
if ($model->status === 'D') {
    $model->updateByPk($model->id, array('status'=>'P'));
?>
<script type="text/javascript">
$(document).ready(function(){
   $('#createModal').modal('show');
});
</script>
<!-- Modal -->
<div class="modal fade" id="createModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                 <h4 class="modal-title">Đăng sự kiện thành công</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-5">
                        <p><strong>CHÚC MỪNG BẠN ĐÃ HOÀN THÀNH ĐĂNG TIN SỰ KIỆN.</strong></p>
                        <p><em>Chúng tôi sẽ tiến hành kiểm duyệt sự kiện trong thời gian sớm nhất.</em></p>
                    </div>
                    <div class="col-xs-7 event-right">
                        <h4>DỊCH VỤ QUẢNG BÁ SỰ KIỆN HÀNG ĐẦU</h4>
                        <p>Nếu bạn muốn:</p>
                        <ul>
                            <li>- Đặt sự kiên lên Top Banner.</li>
                            <li>- Quảng bá sự kiện tới hàng ngàn người biết đến. Keyword Top đầu, Viral Facebook, Forum Seeding v.v.v</li>
                            <li>- Quảng cáo Adword, Facebook Ads sự kiện.</li>
                        </ul>
                        <p>Liên hệ ngay với chúng tôi: <strong class="text-danger">0969.836.599</strong></p>
                        <p>Tham khảo thêm tại <strong><a target="_blank" href="http://www.slideshare.net/dndvietnam/next-topevent-bopbaogiatruyenthong">ĐÂY</a></strong>.</p>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<?php
}
?>